<?php
if (!defined('IN_CONTEXT')) die('access violation error!');
?>
<script type="text/javascript">
<!--
function delete_role(r_id)
{
	if (confirm("想要删除这个角色吗？某些只有此角色的用户将变为未分配角色")) 
	{
		_ajax_request("role", 
		        "doDeleteRole", 
		        {
		            id: r_id
		        }, 
		        on_delete_success, 
		        on_delete_failure);
	}
}

function on_delete_success(response)
{
	response1 = eval("("+response+")");
	var stat = document.getElementById("stat");
	if(response1.result == 'ok')
	{
		alert(response1.sucmsg);
		stat.innerHTML = "OK，正在重定向......";
		reloadPage();
	}
	else if(response1.result == 'error')
	{
		stat.innerHTML = response1.errmsg;
	}
}

function on_delete_failure(response)
{
	var stat = document.getElementById("stat");
	stat.innerHTML = response;
}
-->
</script>
<style type="text/css">
table td {
	 text-align:left;
}
</style>
<div id="stat" style="display:none;"></div>
<p style="margin-bottom:2px;"><a href="index.php?_m=role&_a=addRolePage"><span style="font-size:12px;">添加角色</span></a></p>
<table width="100%" border="0" cellpadding="2" cellspacing="0" bordercolor="#4c4c4c">
	<tr>
		<td>序号</td>	
		<td>角色名</td>
		<td>备注</td>
		<td>操作</td>
	</tr>
<?php 
$i = 1;
foreach($roles as $v)
{
	echo "<tr>";
	if($v['r_role'] == 'admin' || $v['r_role'] == 'unassign')//admin为内置角色（组），不能修改此角色信息,以防角色和授权操作全部不删除的问题
	{
		echo "<td>$i</td><td>{$v['r_alias']}</td><td>{$v['r_desc']}</td><td><a title='{$v['r_alias']}为内置角色不能对其操作' href='index.php?_m=role&_a=doViewRole&r_id={$v['r_id']}' title='查看'><img style='border:none;' src='./images/view.gif'/></a></td>";
	}
	else
	{
		echo "<td>$i</td><td>{$v['r_alias']}</td><td>{$v['r_desc']}</td><td><a title='编辑' href='index.php?_m=role&_a=editRolePage&r_id={$v['r_id']}'><img style='border:none;' src='./images/edit.gif'/></a>&nbsp;<a href='#' title='删除' onclick='delete_role(\"{$v['r_id']}\");'><img style='border:none;' src='./images/cross.gif'/></a></td>";
	}
	echo "</tr>";
	$i++;
}
?>
</table>